package com.tong.embeddedvr.utils;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.tong.embeddedvr.config.VerCodeMsgConfig;

public class MsgSendUtil {

    public static void sendVerMsg(VerCodeMsgConfig verCodeMsgConfig,String telephone,String param){
        System.out.println(verCodeMsgConfig);
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", verCodeMsgConfig.getAccessKeyId(), verCodeMsgConfig.getSecret());
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);
        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", telephone);
        request.putQueryParameter("SignName", verCodeMsgConfig.getSignName());
        request.putQueryParameter("TemplateCode", verCodeMsgConfig.getTemplateCode());
        //模板中传入的json格式的参数
        request.putQueryParameter("TemplateParam", "{code: " + param + "}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}
